Column

Column

---
title: "Dashboard"

output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(flexdashboard)
```

Column {data-width=650}
-----------------------------------------------------------------------

```{r}

data("instacart")

instacart %>%
  group_by(department) %>%
  summarize(item_count = n()) %>%
  filter(item_count > 10000) %>% 
  plot_ly(x = ~department, y = ~item_count, type = "bar") %>% 
  layout(
     title = "Number of items ordered in each department (>10000)",
     xaxis = list(title = "Department"),
     yaxis = list(title = "Item count")
  )
```

Column {data-width=350}
----------------------------------------------------------------------- 

```{r}
instacart %>%
  janitor::clean_names() %>% 
  mutate(
  order_dow = recode(order_dow,
                       "0" = "Sunday",
                       "1" = "Monday",
                       "2" = "Tuesday",
                       "3" = "Wednesday",
                       "4" = "Thursday",
                       "5" = "Friday",
                       "6" = "Saturday")
  ) %>% 
  plot_ly(x = ~order_dow, y = ~order_hour_of_day, type = "box") %>% 
  layout(
    title = "Distribution of orders by hour and day of week",
    xaxis = list(title = "Day of week"),
    yaxis = list(title = "Hour of day")
  )
```

```{r}
instacart %>% 
  janitor::clean_names() %>% 
  mutate(
    order_dow = recode(order_dow,
                       "0" = "Sunday",
                       "1" = "Monday",
                       "2" = "Tuesday",
                       "3" = "Wednesday",
                       "4" = "Thursday",
                       "5" = "Friday",
                       "6" = "Saturday")
  ) %>% 
mutate(
  order_dow = forcats::fct_relevel(order_dow, c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))) %>% 
  filter(product_name %in% c("Apples", "Organic Apples")) %>% 
  group_by(product_name, order_dow) %>% 
  summarize(orders = n()) %>% 
  plot_ly(x = ~order_dow, y = ~orders, color = ~product_name, type = "scatter", mode = "lines") %>% 
  layout(
    title = "Apple vs organic apple orders each day",
    xaxis = list(title = "Day of week"),
    yaxis = list(title = "Orders")
  )
```